package com.blockmeta.bbs.immodule.corebean;

import android.content.Context;

import com.blockmeta.bbs.baselibrary.base.app.BaseApp;
import com.blockmeta.bbs.immodule.greendao.DBHelper;
import com.blockmeta.bbs.immodule.greendao.repository.ChatMessageRepo;
import com.blockmeta.bbs.immodule.greendao.repository.IChatMessageRepo;
import com.blockmeta.bbs.immodule.greendao.repository.IMUserRepo;
import com.blockmeta.bbs.immodule.greendao.repository.ITodoRepo;
import com.blockmeta.bbs.immodule.greendao.repository.IUserRepo;
import com.blockmeta.bbs.immodule.greendao.repository.TodoRepo;

public class IMRepoFactory {

    private static IChatMessageRepo chatMessageRepo;
    private static IUserRepo userRepo;
    private static ITodoRepo todoRepo;
    public static IChatMessageRepo createChatMessageRepo(Context context){
        if(chatMessageRepo != null){
            return chatMessageRepo;
        }else {
            synchronized (IChatMessageRepo.class){
                if(chatMessageRepo == null){
                    chatMessageRepo = new ChatMessageRepo(DBHelper.getInstance(context).getDaoSession().getChatMessageDao()
                            , DBHelper.getInstance(context).getDaoSession().getTalkListTopDao()
                            , DBHelper.getInstance(context).getDb());
                }
            }
        }
        return chatMessageRepo;
    }


    public static IUserRepo createIMUserRepo(Context context){
        if(userRepo == null){
            synchronized (IUserRepo.class){
                if(userRepo == null){
                    userRepo = new IMUserRepo(DBHelper.getInstance(context).getDaoSession().getIMUserEntityDao()
                            , DBHelper.getInstance(context).getDaoSession().getCircleMemberDao()
                            , DBHelper.getInstance(context).getDb());
                }
            }
        }
        return userRepo;

    }

    public static ITodoRepo createTodoRepo(Context context){
        if(todoRepo == null){
            synchronized (ITodoRepo.class){
                if(todoRepo == null){
                    todoRepo = new TodoRepo(DBHelper.getInstance(context).getDaoSession().getTodoDao()
                            , DBHelper.getInstance(context).getDb());
                }
            }
        }
        return todoRepo;
    }
}
